package com.example.one.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.one.mapper.WalletDetailMapper;
import com.example.one.pojo.WalletDetails;
import com.example.one.service.WalletDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Copyright (C), 2017-2022, MIDOU
 * ClassName: WalletDetailServiceImpl
 * Author:   pangshu
 * Date:     2022/10/28 18:20
 * Version: 1.0
 * Description:明细
 */
@Service
public class WalletDetailServiceImpl implements WalletDetailService {
    @Autowired
    private WalletDetailMapper detailMapper;
    /**
     * @Author:pangshu
     * @Description: 添加钱包操作记录
     * @Date:21:18 2022/10/28
     * @Param:
     * @return: java.lang.Integer
     **/
    @Override
    public Integer insertWalletDetail(WalletDetails walletDetails) {
        int insert = detailMapper.insert(walletDetails);
        return insert;
    }

    //通过Id查询
    @Override
    public WalletDetails getDetailById(Integer detailId) {
        WalletDetails walletDetails = detailMapper.selectById(detailId);
        return walletDetails;
    }

    @Override
    public List<WalletDetails> getDetailByUserId(Integer userId) {
        QueryWrapper<WalletDetails> wrapper = new QueryWrapper<>();
        wrapper.eq("payer_id",userId).or().eq("come_id",userId);
        List<WalletDetails> walletDetails = detailMapper.selectList(wrapper);
        return walletDetails;
    }
}
